import router from '@/router'
import { useStore } from '@/store'
import { ElMessage } from 'element-plus'
import { default as jsCookie } from 'js-cookie'

export default function resolveStore () {
  const store = useStore()

  router.beforeEach((to, from, next) => {
    if (to.name === 'login') {
      next()
      return
    }
    let token = jsCookie.get("userToken") as string
    if (token) {
      next()
    } else {
      ElMessage.error("您没有权限")
      next({ name: 'login' })
    }
  })
}